import dayjs from "dayjs";
export function useCurrentData() {
  /**当前时间 */
  const currentDate = ref(dayjs());
  let interval: NodeJS.Timeout;
  setCurrentData();
  onActivated(() => {
    setCurrentData();
  });
  /**设置当前时间 */
  function setCurrentData() {
    console.log("开始更新页面当前时间");
    currentDate.value = dayjs();
    setInterval(() => (currentDate.value = dayjs()), 1000);
  }
  /**清除当前时间定时器 */
  onUnmounted(clear);
  onBeforeRouteLeave(clear);
  function clear() {
    console.log("停止更新页面当前时间");
    clearInterval(interval);
  }
  return { currentDate, clear };
}
